import Foundation
import UIKit
import AVKit
extension UIFont {
    static func Medium(ofSize: CGFloat) -> UIFont {
        return UIFont(name: "PingFangSC-Medium", size: ofSize) ?? UIFont.systemFont(ofSize: ofSize)
    }
    static func Semibold(ofSize: CGFloat) -> UIFont {
        return UIFont(name: "PingFangSC-Semibold", size: ofSize) ?? UIFont.systemFont(ofSize: ofSize)
    }

}

extension AVAsset {

    func generateThumbnail(completion: @escaping (Data?) -> Void) {
        DispatchQueue.global().async {
            let imageGenerator = AVAssetImageGenerator(asset: self)
            let time = CMTime(seconds: 0.0, preferredTimescale: 600)
            let times = [NSValue(time: time)]
            imageGenerator.generateCGImagesAsynchronously(forTimes: times, completionHandler: { _, image, _, _, _ in
                if let image = image {
                    completion(UIImage(cgImage: image).jpegData(compressionQuality: 1.0))
                } else {
                    completion(nil)
                }
            })
        }
    }
}




